package com.bailong.nanny.controller;

import com.bailong.nanny.entity.User;
import com.bailong.nanny.service.UserService;
import com.bailong.nanny.service.impl.UserServiceImpl;

import javax.jws.WebService;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "/allUsers.do",urlPatterns = "/allUsers.do")
public class SelectAllUserServerlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=UTF-8");
        UserService service = new UserServiceImpl();
        List<User>list = service.selectAllUser();
        req.setAttribute("users",list);
        System.out.println("查询成功：" +  list.size());
        req.getRequestDispatcher("/users.jsp").forward(req,resp);
    }
}
